"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from selenium.webdriver.common.by import By

from web_auto_testing.page.base_page import BasePage
from web_auto_testing.page.home_page import HomePage


class LoginPage(BasePage):
    """登录页"""

    _INPUT_USERNAME = (By.XPATH, "//input[@name='user']")
    _INPUT_PASSWORD = (By.XPATH, "//input[@name='password']")
    _BTN_LOGIN = (By.CSS_SELECTOR, ".van-button.van-button--danger.van-button--large")
    _BTN_MAIN = (By.CSS_SELECTOR, ".van-hairline--top-bottom.van-tabbar.van-tabbar--fixed>div:nth-child(1)")

    def login(self):
        """登录"""
        # 打开网页
        self.driver.get("https://litemall.hogwarts.ceshiren.com/vue/index.html#/login/")
        # 输入账号
        self.do_send_keys("user123", self._INPUT_USERNAME)
        # 输入密码
        self.do_send_keys("user123", self._INPUT_PASSWORD)
        # 点击登录
        self.do_find(self._BTN_LOGIN).click()
        # 点击精选
        self.do_find(self._BTN_MAIN).click()
        return HomePage(self.driver)

